package time.code.added;

import java.time.Clock;

/**
 * Description: Clock示例demo
 *
 * @author code-worker
 * @date 2021/08/22 10:27
 */
public class ClockDemo {

    public void getTimeStamp(){
        // 根据系统时间返回当前时间并设置为UTC
        Clock timeStamp = Clock.systemUTC();
        // 根据系统时钟区域返回时间
        Clock time = Clock.systemDefaultZone();
        System.out.println("当前时间戳: "+timeStamp.millis());
        System.out.println("当前时间戳: "+time.millis());
    }

    public void getTimeZone(){
        Clock timeStamp = Clock.systemUTC();
        Clock time = Clock.systemDefaultZone();
        System.out.println("\n当前时区: "+timeStamp.getZone());
        System.out.println("当前时区: "+time.getZone());
    }

    public void getDateTime(){
        Clock timeStamp = Clock.systemUTC();
        Clock time = Clock.systemDefaultZone();
        System.out.println("\n当前时间: "+timeStamp.instant());
        System.out.println("当前时间: "+time.instant());
    }

    public static void main(String[] args) {
        ClockDemo demo = new ClockDemo();
        demo.getTimeStamp();
        demo.getTimeZone();
        demo.getDateTime();
    }

}
